function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

jQuery.fn.autolink = function () {
	return this.each( function(){
		var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
		$(this).html( $(this).html().replace(re, '<a href="$1">$1</a> ') );
	});
}

$(document).ready(function () {
	$('body').autolink();
	
	var timebefore = new Date();
	var numa = $('a').size();
	var numaa = 0;
	var timetook = 0;
	
	var arrlinks = new Array();
	var links;
	$('a').each(function(i) {
		links = 'array_links[]=' + escape($(this).attr('href'));
		$.ajax({
			type: "post",
			url: "linkchecker.php",
			dataType: "text",
			data: links,
			success: function(data) {
				var dead;
				var alive;
				data = data.split("\r\n");
				if (data[0] == 'dead') {
					$("a[href='"+ data[1] +"']").css('background-color','#F00');
					$("a[href='"+ data[1] +"']").attr('href',('http://anonym.to/?'+$("a[href='"+ data[1] +"']").attr('href')));
					numaa++;
				}
				
				if (data[0] == 'alive') {
					$("a[href='"+ data[1] +"']").css('background-color','#0F0');
					$("a[href='"+ data[1] +"']").attr('href',('http://anonym.to/?'+$("a[href='"+ data[1] +"']").attr('href')));
					numaa++;
				}
				
				if (numa == numaa) {
					timetook = (((new Date()) - timebefore)/1000);
				}
				
			}
		});
	});
});